import http from '@/fetch';

const validateTag = async (rule, value, callback) => {
  const existed = await http.get(`/rooms/exist/${value}`, null, false, false);
  if (existed) return callback(new Error("房间号已存在"));
  callback();
}

const validateFloor = (rule, value, callback) => {
  if (value < 1 || value > 99) return callback(new Error("楼层取值范围为1~99"));
  callback();
}

export default {
  tag: [{
      required: true,
      message: "请输入房间号",
      trigger: "blur"
    },
    {
      pattern: /^[\d][\d-]{2,4}$/,
      message: '房间号必须以数字开头，可包含数字和间隔符' - '，长度为3~5位',
      trigger: 'blur'
    },
    {
      validator: validateTag,
      trigger: "blur"
    }
  ],
  type: {
    required: true,
    message: "请选择房间类型",
    trigger: "change"
  },
  isBedMode: {
    required: true,
    message: "请选择是否按床位售卖",
    trigger: "blur"
  },
  floor: [{
      required: true,
      message: "请输入楼层",
      trigger: "blur"
    },
    {
      validator: validateFloor,
      trigger: "blur"
    }
  ]
}
